
<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="utf-8">
        <title>浏览页面</title>
        <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
        <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
    </head>
    <body class="pear-container">
    
        <!-- 顶部查询表单 -->
        
        
        <!-- 数据表格 -->
        <div class="layui-card">
            <div class="layui-card-body">
                <table id="data-table" lay-filter="data-table"></table>
            </div>
        </div>

        <!-- 表格行工具栏 -->
        <script type="text/html" id="table-bar">
            {{# if(d.status==0){}}
            <button class="pear-btn pear-btn-xs tool-btn" lay-event="audit" permission="app.admin.rldistributionofficerslog.audit">审核</button>
            {{# } }}
        </script>

        <script type="text/html" id="createTime">
            {{# if(d.create_time>0){}}
            {{layui.util.toDateString(d.create_time+'000', 'yyyy-MM-dd HH:mm:ss')}}
            {{# } }}
        </script>

        <script type="text/html" id="updateTime">
            {{# if(d.update_time>0){}}
            {{layui.util.toDateString(d.update_time+'000', 'yyyy-MM-dd HH:mm:ss')}}
            {{# } }}
        </script>

        <script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
        <script src="/app/admin/component/pear/pear.js"></script>
        <script src="/app/admin/admin/js/permission.js"></script>
        <script src="/app/admin/admin/js/common.js"></script>
        
        <script>

            // 相关常量
            const PRIMARY_KEY = "id";
            const SELECT_API = "/app/admin/rl-distribution-officers-log/select";
            const AUDIT_URL = "/app/admin/rl-distribution-officers-log/audit";
            
            // 表格渲染
            layui.use(["table", "form", "common", "popup", "util"], function() {
                let table = layui.table;
                let form = layui.form;
                let $ = layui.$;
                let common = layui.common;
                let util = layui.util;
                
				// 表头参数
				let cols = [
                    {
                        title: "ID",align: "left",
                        field: "id",
                        width: '100',
                    },
					{
						title: "用户ID",align: "left",
						field: "member_id",
                        width: '100',
                        hide:true,
					},{
                        title: "昵称",align: "left",
                        field: "nickname",
                        width: '120',
                    },{
                        title: "头像",align: "left",
                        field: "avatar",
                        width: '100',
                        templet: function (d) {
                            return '<img src="'+encodeURI(d['avatar'])+'" style="max-width:32px;max-height:32px;" alt="" />'
                        }
                    },{
						title: "申请人姓名",align: "left",
						field: "real_name",
                        width: '120',
					},{
						title: "申请人电话",align: "left",
						field: "mobile",
                        width: '120',
					},{
						title: "状态",align: "left",
						field: "status",
                        width: '120',
                        templet: function (d) {
                            let css = {"0":"layui-bg-red","1":"layui-bg-green","2":"layui-bg-blue"}[d["status"]];
                            let title = {"0":"待审核","1":"已通过","2":"已拒绝"}[d["status"]];
                            return '<span class="layui-badge '+css+'">'+util.escape(title)+'</span>';
                        }
					},{
						title: "创建时间",align: "left",
						field: "create_time",
                        templet: '#createTime',
                        width: '200',
					},{
                        title: "更新时间",align: "left",
                        field: "update_time",
                        templet: '#updateTime',
                        width: '200',
                    },{
						title: "操作",
						toolbar: "#table-bar",
						align: "center",
						fixed: "right",
						width: 120,
					}
				];
				
				// 渲染表格
				table.render({
				    elem: "#data-table",
				    url: SELECT_API,
				    page: true,
				    cols: [cols],
				    skin: "line",
				    size: "lg",
				    toolbar: "#table-toolbar",
				    autoSort: false,
				    defaultToolbar: [{
				        title: "刷新",
				        layEvent: "refresh",
				        icon: "layui-icon-refresh",
				    }, "filter", "print", "exports"],
				    done: function () {
				        layer.photos({photos: 'div[lay-id="data-table"]', anim: 5});
				    }
				});

                // 编辑或删除行事件
                table.on("tool(data-table)", function(obj) {
                    if (obj.event === "audit") {
                        audit(obj);
                    }
                });

                // 表格顶部搜索事件
                form.on("submit(table-query)", function(data) {
                    table.reload("data-table", {
                        page: {
                            curr: 1
                        },
                        where: data.field
                    })
                    return false;
                });
                
                // 表格顶部搜索重置事件
                form.on("submit(table-reset)", function(data) {
                    table.reload("data-table", {
                        where: []
                    })
                });


                // 表格编辑数据
                let audit = function(obj) {
                    let value = obj.data[PRIMARY_KEY];
                    layer.open({
                        type: 2,
                        title: "审核",
                        shade: 0.1,
                        maxmin: true,
                        area: [common.isModile()?"100%":"500px", common.isModile()?"100%":"450px"],
                        content: AUDIT_URL + "?" + PRIMARY_KEY + "=" + value
                    });
                }

                // 刷新表格数据
                window.refreshTable = function(param) {
                    table.reloadData("data-table", {
                        scrollPos: "fixed"
                    });
                }
            })

        </script>
    </body>
</html>
